package com.vastcom.bmi.action;

import com.vastcom.bmi.to.Parm;
import com.vastcom.bmi.vo.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RestController
public class PublicAction {


    @PostMapping("bmiValue")
    public Result bMiValue(@RequestBody Parm parm) throws Exception {

        float sgf = Float.parseFloat(parm.getSg());
        float tzf = Float.parseFloat(parm.getTz());
        float result = tzf / (sgf * sgf);
        System.out.printf("sgf"+sgf+"tzf="+tzf);
        String suggest = "";

        if (result <= 18.4) {
            suggest = "thin";
        } else if (result > 18.5 && result <= 23.9) {
            suggest = "normal";
        } else if (result >= 24 && result <= 27.9) {
            suggest = "overweight";
        } else {
            suggest = "fat";
        }
        Result r = new Result();
        System.out.println(result);
        r.setSg(sgf);
        r.setTz(tzf);
        r.setResult(result);
        r.setSuggest(suggest);
        return r;

    }


}
